package com.neulogistics.contrib.warehouse.api.application.command.handler;

import com.blackto.lib.mediat.unicast.IRequestHandler;
import com.neulogistics.contrib.warehouse.api.application.command.SourceWarehouseInfoCommand;
import com.neulogistics.contrib.warehouse.api.application.viewmodel.WarehouseViewModel;
import com.neulogistics.contrib.warehouse.api.application.query.IWarehouseQueryService;
import com.neulogistics.contrib.warehouse.api.application.rpc.IWarehouseRPC;
import com.neulogistics.infrastructure.common.serviceresult.BaseResponse;
import com.neulogistics.infrastructure.common.serviceresult.ResultUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class SourceWarehouseInfoCommandHandler implements IRequestHandler<SourceWarehouseInfoCommand, BaseResponse<WarehouseViewModel>> {
    @Resource
    private IWarehouseQueryService warehouseQueryService;

    @Resource
    IWarehouseRPC warehouseRPC;


    @Override
    public BaseResponse<WarehouseViewModel> handle(SourceWarehouseInfoCommand command) {
        Integer sourceWarehouseId = warehouseRPC.getSourceWarehouseId(command.circulationId, command.resAim);
        WarehouseViewModel warehouseViewModel = warehouseQueryService.getById(sourceWarehouseId);

        return ResultUtils.success(warehouseViewModel);
    }
}
